package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClassOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 1 统计员工职位人数
     *
     * @return
     */
    @Override
    public JobOption getEmpJobData() {
        //1调用Mapper接口
        List<Map<String, Object>> list = empMapper.countEmpJobData();//map：pos=部门 num=数量
        //2.解析并封装数据并返回
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobOption(jobList, dataList);

    }

    /**
     * 2 统计员工性别人数
     */
    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }


    /**
     * 3 统计班级人数
     */
    @Override
    public ClassOption getStudentCountData() {
        //1调用Mapper接口
        List<Map<String, Object>> list = studentMapper.countStudentCountData();
        //2.解析并封装数据并返回
        List<Object> peopleList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> nameList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new ClassOption(peopleList, nameList);
    }


    /**
     * 4 学生学历统计
     */
    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
       return studentMapper.getStudentDegreeData();
    }


}
